package com.ruoyi.project.goods.controller;


import cn.mabach.goods.entity.SkuStockEntity;
import cn.mabach.result.PageResult;
import cn.mabach.result.RS;
import com.ruoyi.project.goods.feign.SkuStockServiceFeign;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * sku的库存
 *
 * @author chenshun
 * @email 176468159@qq.com
 * @date 2019-12-29 02:40:20
 */
@RestController
@RequestMapping("/sku")
public class SkuStockController {
    @Autowired
    private SkuStockServiceFeign skuStockService;



    /**
        * 分页列表
        */
    @GetMapping(value = "/list")
    @PreAuthorize("@ss.hasPermi('pms:skustock:read')")
    public RS<PageResult<SkuStockEntity>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {

        RS<PageResult<SkuStockEntity>> pageResultRS = skuStockService.queryPage(keyword, pageNum, pageSize);

        return pageResultRS;
    }



//    /**
//     * 信息
//     */
//
//    @GetMapping(value = "/{id}")
//    @PreAuthorize("@ss.hasPermi('pms:skustock:read')")
//    public RS<SkuStockEntity> getItem(@PathVariable("id") Long id) {
//        return skuStockService.getByIdE(id);
//    }
//




    /**
     * 保存
     */
    @PostMapping(value = "/create")
    @PreAuthorize("@ss.hasPermi('pms:skustock:create')")
    public RS create(@RequestBody SkuStockEntity skuStockEntity) {

        RS rs = skuStockService.saveE(skuStockEntity);

        return rs;
    }



    /**
     * 修改
     */
//    @PostMapping(value = "/update/{id}")
//    @PreAuthorize("@ss.hasPermi('pms:skustock:update')")
//    public RS update(@PathVariable("id") Long id, @RequestBody SkuStockEntity entity) {
//        entity.setId(id);
//        RS rs = skuStockService.updateByIdE(entity);
//
//        return rs;
//    }



    /*
     * 根据商品编号及编码模糊搜索sku库存
     * */

    @RequestMapping(value = "/{pid}", method = RequestMethod.GET)
    @PreAuthorize("@ss.hasPermi('pms:skustock:read')")
    public RS<List<SkuStockEntity>> getList(@PathVariable("pid") Long pid, @RequestParam(value = "keyword",required = false) String keyword){
        RS<List<SkuStockEntity>> list = skuStockService.getList(pid, keyword);
        return list;
    }


    @RequestMapping(value ="/update/{pid}",method = RequestMethod.POST)
    @PreAuthorize("@ss.hasPermi('pms:skustock:read')")
    public RS update(@PathVariable("pid") Long pid,@RequestBody List<SkuStockEntity> skuStockList){
       return skuStockService.update(pid,skuStockList);
    }




}
